'use strict';
angular.module('app')
    .controller('hotSearchController', [ '$rootScope', '$scope', '$http', '$state','$timeout',
        function($rootScope, $scope, $http, $state, $timeout) {

            $scope.title = '热搜词配置';
            $scope.searchParams = { };
            $scope.loading = false;
            $scope.param = {};

            $scope.search = function () {
                $scope.selected = [];
                $scope.loading = true;

                $("#allCheck").attr("checked", false);
                $.ajax({
                    url: $scope.app.project_name + '/hotSearch/list',
                    data: $scope.searchParams
                }).then(function (result) {
                    console.log(result);
                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.pageInfo = result.data;
                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }

            $scope.search();

            $scope.searchRe = function () {
                $scope.loading = true;
                $scope.searchParams.pageNum = 1;
                $.ajax({
                    url : $scope.app.project_name+'/hotSearch/list',
                    data: $scope.searchParams
                }).then(function(result) {

                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.pageInfo = result.data;
                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }



            $scope.clearSearch = function() {
                $scope.searchParams= { };
                $scope.search();
            }


            $scope.enableUpdate = function (hotNo,$event) {
                $.ajax({
                    url : $scope.app.project_name+'/hotSearch/enableUpdate',
                    data: {hotNo:hotNo,enable:$event.target.checked?'Y':'N'}
                }).then(function(result) {
                    $scope.loading = false;
                    $scope.alertModal({"content":"操作成功"});
                    if (result.httpCode != 200) {
                        $scope.alertModal(result.msg);
                    }
                    $scope.search();
                });
            }
            // 翻页
            $scope.pagination = function (pageNo) {
                $scope.searchParams.pageNum = pageNo;
                $scope.search();
            };
        }
        ]);